from typing import List, Dict
import threading


def runActionGroup(action_group: List[dict]):
    """
    接收动作组列表，运行动作组
    :param action_group: 动作组列表，demo:[{"servo_id": 1, "pulse": 100, "use_time": 500}, ...]
    :return:
    """
    from utils.HiwonderSDK import Board
    for action in action_group:
        servo_id, pulse, use_time = action['servo_id'], action['pulse'], action['use_time']
        print(servo_id, pulse, use_time)
        Board.setBusServoPulse(servo_id, pulse, use_time)


def startRunActionGroup(action_group: List[dict]):
    """
    开一个线程运行动作组
    :param action_group: 动作组列表，demo:[{"servo_id": 1, "pulse": 100, "use_time": 500}, ...]
    """
    th1 = threading.Thread(target=runActionGroup, args=(action_group, ))
    print(f'线程{th1}')
    th1.start()
